package com.vcc.web.core.queue.pingpong.model;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;

import java.math.BigDecimal;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

@Data
@Setter
@Getter
public class OpenCard implements Delayed {

    private String orderId;

    private String ppCardId;

    private Long cardId;

    private Long userId;

    private BigDecimal amount;

    private String remark;

    private Long time;

    private Long cardholderId;

    public OpenCard(String ppCardId, Long time,Long cardId, Long userId, String orderId, BigDecimal amount,String remark,Long cardholderId) {
        this.time = System.currentTimeMillis() + time;
        this.ppCardId = ppCardId;
        this.amount = amount;
        this.orderId = orderId;
        this.userId = userId;
        this.cardId = cardId;
        this.remark = remark;
        this.cardholderId = cardholderId;
    }

    @Override
    public long getDelay(@NotNull TimeUnit unit) {
        return unit.convert(time - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(@NotNull Delayed o) {
        return Long.compare(getDelay(TimeUnit.MILLISECONDS), o.getDelay(TimeUnit.MILLISECONDS));
    }
}
